package com.person.jc.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MyMD5 {

	public static String myMD5(String content) {
		return Encrypt(content, "");
	}
	
	public static String myMD52(String content,String salt){
		return MyMD5.myMD5(MyMD5.myMD5(new String(content))+ salt);
	}
	
	/**加密字符**/
    private static String Encrypt(String strSrc, String encName){
        MessageDigest md = null;
        String encStr = null;

        byte[] bt = strSrc.getBytes();
        try{
            if (Utils.isEmpty(encName)){
                encName = "MD5";
            }
            md = MessageDigest.getInstance(encName);
            md.update(bt);
            encStr = bytes2Hex(md.digest()); // to HexString
        }
        catch (NoSuchAlgorithmException e){
            System.out.println("Invalid algorithm.");
        }
        return encStr;
    }
    /**转换为16进制字符**/
    private static String bytes2Hex(byte[] bts){
        String des = "";
        String tmp = null;
        for (int i = 0; i < bts.length; i++){
            tmp = (Integer.toHexString(bts[i] & 0xFF));
            if (tmp.length() == 1){
                des += "0";
            }
            des += tmp;
        }
        return des;
    }
    
    public static void main(String[] args) {
        String str = myMD5("111111");
        System.out.println(str);
    }
}